﻿/*
  In App.xaml:
  <Application.Resources>
      <vm:ViewModelLocatorTemplate xmlns:vm="clr-namespace:CDFWPUG.ViewModel"
                                   x:Key="Locator" />
  </Application.Resources>
  
  In the View:
  DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
  
  OR (WPF only):
  
  xmlns:vm="clr-namespace:CDFWPUG.ViewModel"
  DataContext="{Binding Source={x:Static vm:ViewModelLocatorTemplate.ViewModelNameStatic}}"
*/

namespace CDFWPUG.ViewModel
{
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// <para>
    /// Use the <strong>mvvmlocatorproperty</strong> snippet to add ViewModels
    /// to this locator.
    /// </para>
    /// <para>
    /// In Silverlight and WPF, place the ViewModelLocatorTemplate in the App.xaml resources:
    /// </para>
    /// <code>
    /// &lt;Application.Resources&gt;
    ///     &lt;vm:ViewModelLocatorTemplate xmlns:vm="clr-namespace:CDFWPUG.ViewModel"
    ///                                  x:Key="Locator" /&gt;
    /// &lt;/Application.Resources&gt;
    /// </code>
    /// <para>
    /// Then use:
    /// </para>
    /// <code>
    /// DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
    /// </code>
    /// <para>
    /// You can also use Blend to do all this with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// <para>
    /// In <strong>*WPF only*</strong> (and if databinding in Blend is not relevant), you can delete
    /// the Main property and bind to the ViewModelNameStatic property instead:
    /// </para>
    /// <code>
    /// xmlns:vm="clr-namespace:CDFWPUG.ViewModel"
    /// DataContext="{Binding Source={x:Static vm:ViewModelLocatorTemplate.ViewModelNameStatic}}"
    /// </code>
    /// </summary>
    public class ViewModelLocator
    {

        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
            ////if (ViewModelBase.IsInDesignModeStatic)
            ////{
            ////    // Create design time view models
            ////}
            ////else
            ////{
            ////    // Create run time view models
            ////}

           
        }

        private static panMainViewModel _panMain;

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        public static panMainViewModel PanMainStatic
        {
            get
            {
                if (_panMain == null)
                {
                    CreatePanMain();
                }

                return _panMain;
            }
        }

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public panMainViewModel PanMain
        {
            get
            {
                return PanMainStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the ViewModelPropertyName property.
        /// </summary>
        public static void ClearPanMain()
        {
            if (_panMain != null)
            {
                _panMain.Cleanup();
                _panMain = null;
            }
            
        }

        /// <summary>
        /// Provides a deterministic way to create the ViewModelPropertyName property.
        /// </summary>
        public static void CreatePanMain()
        {
            if (_panMain == null)
            {
                _panMain = new panMainViewModel();
            }
        }

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void Cleanup()
        {
            ClearPanMain();
            ClearPageMeeting();
            ClearPageGroupApps();
            ClearPageNews();
        }


        #region pageMeeting
 private static pageMeetingViewModel _pageMeeting;

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        public static pageMeetingViewModel pageMeetingStatic   
        {
            get
            {
                if (_pageMeeting == null)
                {
                    CreatePageMeeting();
                }

                return _pageMeeting;
            }
        }

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public pageMeetingViewModel pageMeeting
        {
            get
            {
                return pageMeetingStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the ViewModelPropertyName property.
        /// </summary>
        public static void ClearPageMeeting()
        {
            if (_pageMeeting != null)
            {
                _pageMeeting.Cleanup();
                _pageMeeting = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the ViewModelPropertyName property.
        /// </summary>
        public static void CreatePageMeeting()
        {
            if (_pageMeeting == null)
            {
                _pageMeeting = new pageMeetingViewModel();
            }
        }


        #endregion

        #region PageGroupApps
        private static pageGroupAppsViewModel _pageGroupApps;

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        public static pageGroupAppsViewModel PageGroupAppsStatic
        {
            get
            {
                if (_pageGroupApps == null)
                {
                    CreatePageGroupApps();
                }

                return _pageGroupApps;
            }
        }

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public pageGroupAppsViewModel PageGroupApps
        {
            get
            {
                return PageGroupAppsStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the ViewModelPropertyName property.
        /// </summary>
        public static void ClearPageGroupApps()
        {
            if (_pageGroupApps != null)
            {
                _pageGroupApps.Cleanup();
                _pageGroupApps = null;
            }
            
        }

        /// <summary>
        /// Provides a deterministic way to create the ViewModelPropertyName property.
        /// </summary>
        public static void CreatePageGroupApps()
        {
            if (_pageGroupApps == null)
            {
                _pageGroupApps = new pageGroupAppsViewModel();
            }
        }

        #endregion

        #region PageNews
        private static pageNewsViewModel  _pageNews;

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        public static pageNewsViewModel PageNewsStatic
        {
            get
            {
                if (_pageNews == null)
                {
                    CreatePageNews();
                }

                return _pageNews;
            }
        }

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public pageNewsViewModel PageNews
        {
            get
            {
                return PageNewsStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the ViewModelPropertyName property.
        /// </summary>
        public static void ClearPageNews()
        {
            if (_pageNews != null)
            {
                _pageNews.Cleanup();
                _pageNews = null;
            }
            
        }

        /// <summary>
        /// Provides a deterministic way to create the ViewModelPropertyName property.
        /// </summary>
        public static void CreatePageNews()
        {
            if (_pageNews == null)
            {
                _pageNews = new pageNewsViewModel();
            }
        }

        #endregion


        #region PageShare
        private static pageShareViewModel  _PageShare;

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        public static pageShareViewModel  PageShareStatic
        {
            get
            {
                if (_PageShare == null)
                {
                    CreatePageShare();
                }

                return _PageShare;
            }
        }

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public pageShareViewModel  PageShare
        {
            get
            {
                return PageShareStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the ViewModelPropertyName property.
        /// </summary>
        public static void ClearPageShare()
        {
            if (_PageShare  != null)
            {
                _PageShare.Cleanup();
                _PageShare = null;
            }

        }

        /// <summary>
        /// Provides a deterministic way to create the ViewModelPropertyName property.
        /// </summary>
        public static void CreatePageShare()
        {
            if (_PageShare == null)
            {
                _PageShare = new pageShareViewModel();
            }
        }

        #endregion

        #region PageLinks
        private static pageLinksViewModel _PageLinks;

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        public static pageLinksViewModel PageLinksStatic
        {
            get
            {
                if (_PageLinks == null)
                {
                    CreatePageLinks();
                }

                return _PageLinks;
            }
        }

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public pageLinksViewModel PageLinks
        {
            get
            {
                return PageLinksStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the ViewModelPropertyName property.
        /// </summary>
        public static void ClearPageLinks()
        {
            if (_PageLinks != null)
            {
                _PageLinks.Cleanup();
                _PageLinks = null;
            }

        }

        /// <summary>
        /// Provides a deterministic way to create the ViewModelPropertyName property.
        /// </summary>
        public static void CreatePageLinks()
        {
            if (_PageLinks == null)
            {
                _PageLinks = new pageLinksViewModel();
            }
        }

        #endregion




        #region PageAbout
        private static pageAboutViewModel _PageAbout;

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        public static pageAboutViewModel PageAboutStatic
        {
            get
            {
                if (_PageAbout == null)
                {
                    CreatePageAbout();
                }

                return _PageAbout;
            }
        }

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public pageAboutViewModel PageAbout
        {
            get
            {
                return PageAboutStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the ViewModelPropertyName property.
        /// </summary>
        public static void ClearPageAbout()
        {
            if (_PageAbout != null)
            {
                _PageAbout.Cleanup();
                _PageAbout = null;
            }

        }

        /// <summary>
        /// Provides a deterministic way to create the ViewModelPropertyName property.
        /// </summary>
        public static void CreatePageAbout()
        {
            if (_PageAbout == null)
            {
                _PageAbout = new pageAboutViewModel();
            }
        }

        #endregion


    }
}